﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LabMS.BLL;
using LabMS.Model;
using System.Collections.Generic;
using ExtendBLL;

namespace LabMS.Web
{
    public partial class TeacherList : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                bind("1=1");
            }
        }


        public void bind(string strWhere)
        {
            List<LabMS.Model.Teacher> listteachermodule = new
                List<LabMS.Model.Teacher>();
            LabMS.BLL.Teacher bteacher = new LabMS.BLL.Teacher();
            listteachermodule = bteacher.GetModelList(strWhere + " order by ID desc ");
            GridViewDic.DataSource = listteachermodule;
            GridViewDic.DataBind();
        }

        protected void GridViewDic_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridViewDic.PageIndex = e.NewPageIndex;
            if (tbKeyWord.Text.Trim().Equals(""))
            {
                bind("1=1");
            }
            else
            {
                string strwhere = " like ";
                string strcondition = ddlSType.SelectedValue;
                if (strcondition == "0")
                {
                    strwhere = " Teacher_Code " + strwhere;
                }
                else
                {
                    strwhere = " Teacher_Name " + strwhere;
                }
                strwhere = strwhere + " '%" + tbKeyWord.Text.Trim() + "%' ";

                bind(strwhere);
            }
        }

        protected void GridViewDic_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
                //e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");

                e.Row.Attributes.Add("OnDblClick", "DbClickEvent('" + e.Row.Cells[0].Text + "','" + e.Row.Cells[1].Text + "','" + GridViewDic.DataKeys[GridViewDic.DataKeys.Count-1].Value.ToString() + "')");
                e.Row.Attributes["style"] = "Cursor:pointer";
            }

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strwhere = " like ";
            string strcondition = ddlSType.SelectedValue;
            if (strcondition == "0")
            {
                strwhere = " Teacher_Code " + strwhere;
            }
            else
            {
                strwhere = " Teacher_Name " + strwhere;
            }
            strwhere = strwhere + " '%" + tbKeyWord.Text.Trim() + "%' ";

            bind(strwhere);
        }
    }
}

